﻿using Basic.FlowDAL;
using Basic.FlowRemoteModel.NodeFormData.Model;
using WeDonekRpc.Helper;

namespace Basic.FlowCollect.lmpl
{
    internal class FlowAppFormRelationCollect : IFlowAppFormRelationCollect
    {
        private readonly IFlowAppFormRelationDAL _BasicDAL;

        public FlowAppFormRelationCollect ( IFlowAppFormRelationDAL basicDAL )
        {
            this._BasicDAL = basicDAL;
        }
        public DataRelation[] Gets ( long appId )
        {
            return this._BasicDAL.Gets<DataRelation>(a => a.AppId == appId);
        }
        public void Sync ( long appId, DataRelation[] adds )
        {
            if ( this._BasicDAL.IsExists(a => a.AppId == appId) )
            {
                this._BasicDAL.Set(appId, adds);
            }
            else
            {
                this._BasicDAL.Add(appId, adds);
            }
        }
        public void Clear ( long appId )
        {
            long[] ids = this._BasicDAL.Gets(a => a.AppId == appId, a => a.Id);
            if ( ids.IsNull() )
            {
                return;
            }
            this._BasicDAL.Delete(ids);
        }
    }
}
